<template src="./index.html"></template>

<script>
import medicalRecordBaseInfoService from "../../../../../_services/medicalRecordBaseInfo.service";
import medicalRecordCurrentStatusService from "../../../../../_services/medicalRecordCurrentStatus.service";
import medicalRecordMenstrualHistoryService from "../../../../../_services/medicalRecordMenstrualHistory.service";
import medicalRecordChildbearingHistoryService from "../../../../../_services/medicalRecordChildbearingHistory.service";
import medicalRecordMarriageService from "../../../../../_services/medicalRecordMarriage.service";
import medicalRecordOperationHistoryService from "../../../../../_services/medicalRecordOperationHistory.service";
import medicalRecordFamilyMedicalHistoryService from "../../../../../_services/medicalRecordFamilyMedicalHistory.service";
import medicalRecordTestTubeInfoService from "../../../../../_services/medicalRecordTestTubeInfo.service";
import domtoimage from "dom-to-image";
export default {
  name: "TianDingPatientMeMedicalDetailComponent",
  data() {
    return {
      load: false,
      currDate: this.utils$.getCurrentDate(),
      user: {},
      baseInfoList: {},
      currentStatusList: {},
      menstrualHistoryList: {},
      childbearingHistoryList: [],
      marriageList: {},
      operationHistoryList: [],
      familyHistoryList: [],
      testTubeInfoList: [],
      infectionProjectList: [
        {
          key: -1,
          value: "未查待补",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 0,
          value: "均为阴性",
          isRadio: true,
          check: false,
          show: true
        },
        {
          key: 1,
          value: "乙肝",
          isRadio: false,
          check: true,
          show: true
        },
        {
          key: 2,
          value: "丙肝",
          isRadio: false,
          check: false,
          show: true
        },
        {
          key: 3,
          value: "艾滋",
          isRadio: false,
          check: true,
          show: true
        },
        {
          key: 4,
          value: "梅毒",
          isRadio: false,
          check: false,
          show: true
        }
      ]
    };
  },
  mounted() {
    this.user = JSON.parse(this.local$.getItem("tdUser"));
    this.getMedical(this.user.UserID);
  },
  methods: {
    getMedical(UserID) {
      this.indicator$.open("正在组织数据...");
      let myThis = this;
      let params = {};
      params.userid = UserID;
      params.UserID = UserID;
      params.userID = UserID;

      let baseInfo = medicalRecordBaseInfoService.getBaseInfoByUserId(params);
      let currentStatus = medicalRecordCurrentStatusService.getCurrentStatusByUserID(
        params
      );
      let menstrualHistory = medicalRecordMenstrualHistoryService.getMenstrualHistoryByUserID(
        params
      );
      let childbearingHistory = medicalRecordChildbearingHistoryService.getChildbearingHistoryByUserID(
        params
      );
      let marriage = medicalRecordMarriageService.getMarriageListByUserID(
        params
      );
      let operationHistory = medicalRecordOperationHistoryService.getOperationHistoryByUserID(
        params
      );
      let familyHistory = medicalRecordFamilyMedicalHistoryService.getFamilyMedicalHistoryListByUserID(
        params
      );
      let testTubeInfo = medicalRecordTestTubeInfoService.getTestTubeInfoListByUserID(
        params
      );

      let response = this.http$.spread(function(
        baseInfo,
        currentStatus,
        menstrualHistory,
        childbearingHistory,
        marriage,
        operationHistory,
        familyHistory,
        testTubeInfo
      ) {
        console.log("baseInfo基本信息：", baseInfo.Data);
        myThis.baseInfoList = myThis.utils$.dataFormat(baseInfo.Data);
        myThis.baseInfoList.Age = myThis.utils$.getAge(myThis.user.Birthday);
        myThis.baseInfoList.MateAge = myThis.utils$.getAge(
          myThis.user.MateBirthDay
        );
        myThis.baseInfoList.BMI = myThis.utils$.getBMI(
          myThis.baseInfoList.Weight,
          myThis.baseInfoList.Height
        );

        console.log("currentStatus目前状态：", currentStatus.Data);
        myThis.currentStatusList = myThis.utils$.dataFormat(currentStatus.Data);

        console.log("menstrualHistory月经史：", menstrualHistory.Data);
        myThis.menstrualHistoryList = myThis.utils$.dataFormat(
          menstrualHistory.Data
        );

        console.log("childbearingHistory生育史：", childbearingHistory.Data);
        myThis.childbearingHistoryList = childbearingHistory.Data;

        console.log("marriage婚育史：", marriage.Data);
        myThis.marriageList = myThis.utils$.dataFormat(marriage.Data);

        console.log("operationHistory既往史：", operationHistory.Data);
        myThis.operationHistoryList = operationHistory.Data;

        console.log("familyHistory家族病史：", familyHistory.Data);
        myThis.familyHistoryList = familyHistory.Data;

        console.log("testTubeInfo试管详情：", testTubeInfo.Data);
        myThis.testTubeInfoList = testTubeInfo.Data;
        myThis.load = true;
        myThis.indicator$.close();
      });

      this.http$
        .all([
          baseInfo,
          currentStatus,
          menstrualHistory,
          childbearingHistory,
          marriage,
          operationHistory,
          familyHistory,
          testTubeInfo
        ])
        .then(response);
    },
    showItem(item) {
      let flag = false;
      if (item) {
        let arr = item.split(",");
        arr.forEach(element => {
          switch (element) {
            case "未着床":
            case "生化":
            case "宫外孕":
            case "葡萄胎":
            case "主动放弃":
              flag = true;
              break;
            default:
              flag = false;
              break;
          }
        });
      }
      return flag;
    },
    btnClick() {
      this.indicator$.open("正在生成...");
      //点击跳转页面，在新页面展示并下载，现在完成后返回下载页面
      //以下逻辑均为测试，需修改
      let self = this;
      // let card_target = this.$refs.copyCardArea;
      // domtoimage.toPng(card_target).then(dataUrl => {
      //   //andriod
      //   if (dataUrl != "error") {
      //     // alert("domtoimage");
      //     self.imgUrl = dataUrl;
      //     self.isDownloadImg = true;
      //   }
      //   // ios
      //   else {
      //     let b64;
      //     this.html2canvas$(card_target, {
      //       useCORS: true
      //     })
      //       .then(function(canvas) {
      //         try {
      //           b64 = canvas.toDataURL("image/png");
      //         } catch (err) {
      //           console.log(err);
      //           // alert(err)
      //         }
      //         self.imgUrl = b64;
      //         self.isDownloadImg = true;
      //       })
      //       .catch(function onRejected(error) {});
      //   }
      // });
      // domtoimage
      //   .toJpeg(document.getElementById("table-box"), { quality: 0.95 })
      //   .then(function(dataUrl) {
      //     alert(dataUrl);
      //     // var link = document.createElement("a");
      //     // link.download = "my-image-name.jpeg";
      //     // link.href = dataUrl;
      //     // link.click();
      //   });
      this.html2canvas$(document.getElementById("table-box"), {
        scale: 2,
        logging: false,
        useCORS: true
      }).then(canvas => {
        var dataURL = canvas.toDataURL("image/png");
        this.local$.removeItem("medicalDownload");
        this.local$.setItem("medicalDownload", dataURL);
        this.$emit("change", "download");
        this.indicator$.close();
      });
    }
  }
};
</script>

